
#ifndef _MEMBER_BFILEDIALOG_H_
#define _MEMBER_BFILEDIALOG_H_

#include <BMap>
#include <BPoint>
#include <BString>
#include <BEntry>
#include <BFolder>
#include <BLabel>
#include <BButton>
#include <BLineEdit>
#include <BIcon>
#include <BTreeWidget>
#include <BListWidget>
#include <BTableWidget>
#include <BTableItem>
#include <BScrollBar>
#include <BComboBox>
#include <BHBoxLayout>
#include <BVBoxLayout>
#include <BFileDialog>

namespace BWE
{
	struct EntryInfo
	{
		inline EntryInfo()
		{
			ready = false;
		}
		inline void clear()
		{
			ready = false;
			entry = 0;
			image = 0;
			typeStr.clear();
			timeStr.clear();
			sizeStr.clear();
			t_typeStr.clear();
		}

		inline bool operator == (BEntry* entry) const
		{
			return this->entry == entry;
		}

		bool			ready;
		BEntryHolder	entry;
		BImageHolder	image;
		BString			typeStr;
		BString			timeStr;
		BString			sizeStr;
		BString			t_typeStr;
	};

	class member_BFileDialog : public BObject
	{
		friend class BFileDialog;
	public:
		member_BFileDialog(BFileDialog* fileDialog);
		~member_BFileDialog();

		const char* typeName(BEntry* entry);
		BIcon* iconOf(BObject* object);
		BListItem* symbolItem(const BString& path);
		bool checkImage(EntryInfo& info) const;

		void resetDisks();
		void freshListItems();
		void freshTreeItem(BTreeItem* item);
		void freshTableItems();
		void freshBackFrontButton();
		void arrangeTableItems();

		void openFolder(const BString& path);
		void selectEntries();

		void slotBackButtonClicked();
		void slotFrontButtonClicked();
		void slotAboveButtonClicked();

		void slotPathTextChanged(BObject* object, const BValue& value);
		void slotViewTextChanged(BObject* object, const BValue& value);
		void slotListItemClicked(BObject* object, const BValue& value);
		void slotTreeItemClicked(BObject* object, const BValue& value);
		void slotTreeItemDoubleClicked(BObject* object, const BValue& value);

		void slotTableWidgetFramed(BObject* object, const BValue& value);
		void slotTableWidgetResized(BObject* object, const BValue& value);
		void slotTableItemClicked(BObject* object, const BValue& value);
		void slotTableItemHovered(BObject* object, const BValue& value);
		void slotTableItemDoubleClicked(BObject* object, const BValue& value);
		void slotTableWidgetSelectionChanged(BObject* object, const BValue& value);

		void slotScrollAreaChanged(BObject* object, const BValue& value);
		void slotItemEditFocused(BObject* object, const BValue& value);
		void slotItemEditFinished(BObject* object, const BValue& value);
		void slotNameEdited(BObject* object, const BValue& value);
		void slotNameFilterChanged(BObject* object, const BValue& value);

		void slotOkClicked();
		void slotCancleClicked();

	public:
		BFileDialog*			boss;
		Attrib					attribFilter;
		BString					nameFilter;
		BStringArray			fileExts;
		BString					imageExts;
		bool					selectMultiple;
		BStringArray			pathRecords;
		int						pathIndex;
		BStringList				entryNames;
		bool					dirtyStyle;
		const BStyle*			style;

		BHBoxLayout*			topLayout;
		BButton*				prevButton;
		BButton*				nextButton;
		BButton*				aboveButton;
		BComboBox*				pathComboBox;
		BComboBox*				viewComboBox;

		BListWidget*			listWidget;
		BTreeWidget*			treeWidget;
		BTableWidget*			tableWidget;
		BHBoxLayout*			splitLayout;
		BLineEdit*				nameEdit;
		BComboBox*				filterComboBox;
		BButton*				okButton;
		BButton*				cancleButton;
		BHolder<BLineEdit>		itemEdit;

		BArray<EntryInfo>		entryInfos;
		BTableItemHolderArray	tableItems;
		BIconHolder				unknownIcon;
	};
}

#endif